/**
 * 函数生成器, Generator案例
 */

 const ajaxQuery = (url) => {
  return new Promise((resolve, reject) => {
    const http = new XMLHttpRequest();
    http.open("GET", url);
    http.responseType = "json";
    http.onload = function () {
      if (this.status === 200) {
        resolve(this.response);
      } else {
        reject(new Error(this.statusText));
      }
    };
    http.send()
  });
};

function * test(){
  const res = yield ajaxQuery('/07-test/data.json');
  console.log(res)
  const res2 = yield ajaxQuery('/07-test/data2.json');
  console.log(res2)
}

const ger = test();
const result = ger.next();
if(result.done) return;
result.value.then(res=>{
  console.log(res)
  const result2 = ger.next();
  if(result2.done) return;
  result2.value.then(res2=>{
    console.log(res2)
  })
})